#include <stdarg.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>

#include "pub.h"
#include <core_api.h>

E_LOGLEVEL_TYPE g_LogLevel = E_LOGLEVEL_OFF;

BEST_VOID CORE_LogWrite(const char *filePath, const char *fileName, int lines,
                        const char *function, const char *format, ...)
{
    FILE *  pFile = fopen(filePath, "a+");
    va_list arg;
    va_start(arg, format);
    time_t     time_log = time(NULL);
    struct tm *tm_log   = localtime(&time_log);
    fprintf(pFile, "%04d-%02d-%02d %02d:%02d:%02d [%s:%d %s]\t",
            tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday,
            tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec, fileName, lines,
            function);
    vfprintf(pFile, format, arg);
    fprintf(pFile, "\n");
    va_end(arg);
    fflush(pFile);
    fclose(pFile);
}
